package com.example.testing.myphonestatelistener;

import android.app.Instrumentation;

import android.os.RemoteException;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiObjectNotFoundException;


import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static java.lang.Thread.sleep;

/**
 * Created by hunan.liu on 2017/6/30.
 */
@RunWith(AndroidJUnit4.class)
public class TestCase {
    Instrumentation instrumentation;
    UiDevice device;


    public static void sleep(int msecond) {
        try {
            Thread.sleep(msecond);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }




        @Before
        public void setup() throws RemoteException {
            device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
            //context=InstrumentationRegistry.getTargetContext();
            device.wakeUp();
            sleep(2000);
            int width = device.getDisplayWidth();
            int hight = device.getDisplayHeight();
            device.swipe(width / 2, hight, width / 2, 15 * hight / 20, 5);

            device.pressBack();
            sleep(500);
            device.pressBack();
            sleep(500);
            device.pressHome();
            sleep(1500);
        }





    @Test
    //第一次进入电话
    public void firstintophone() throws UiObjectNotFoundException {
        UiObject2 phone = device.findObject(By.text("电话"));
        phone.click();
        sleep(1500);
        while (true){
            UiObject2 Recents= device.findObject(By.text("Recents"));
            UiObject2 Contacts= device.findObject(By.text("Contacts"));
            Recents.click();
            sleep(500);
            Contacts.click();
        }

    }
}
